﻿CREATE PROCEDURE [dbo].[SecurityAuthority_InsertUpdate]

	@id					BIGINT,

	@name				VARCHAR (0060), 

	@description		VARCHAR (0999),


	@securityAuthorityType		INT, 

	@protocol					VARCHAR (0060),

	@serverName					VARCHAR (0060),

	@domain						VARCHAR (0060),


	@modifiedId					VARCHAR (0060)

AS

	BEGIN 

		MERGE SecurityAuthority

			USING (SELECT @id) AS Source (Id)

				ON SecurityAuthority.Id = Source.Id

			WHEN MATCHED THEN 

				UPDATE SET 

					Name = @name,

					Description = @description,

					SecurityAuthorityType = @securityAuthorityType,

					Protocol = @protocol,

					ServerName = @serverName, 

					Domain = @domain,

					ModifiedId = @modifiedId,

					ModifiedDateTime = GETDATE ()

			WHEN NOT MATCHED THEN 

				INSERT (Name, Description, SecurityAuthorityType, Protocol, ServerName, Domain, CreateId, CreateDateTime, ModifiedId, ModifiedDateTime) 

					VALUES (@name, @description, @securityAuthorityType, @protocol, @serverName, @domain, @modifiedId, GETDATE (), @modifiedId, GETDATE())

		; -- MERGE ( END )


	END

	